package com.yiyang.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yiyang.mapper.BedMapper;
import com.yiyang.mapper.RoomMapper;
import com.yiyang.pojo.Bed;
import com.yiyang.pojo.vo.PageResult;
import com.yiyang.pojo.vo.Result;
import com.yiyang.service.BedService;
import com.yiyang.utils.BizCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class BedServiceImpl extends ServiceImpl<BedMapper, Bed> implements BedService{
    @Autowired
    private BedMapper bedMapper;
    @Autowired
    private RoomMapper roomMapper;

    @Override
    public Result<Bed> getBedById(Integer id) {
        Bed bed = this.getById(id);
        if(bed != null){
            return Result.success();
        }
        return Result.fail();
    }

    @Override
    public Result<PageResult<List<Bed>>> getAllBed(Integer currentPage, Integer pageSize, String num, Integer brid) {
        return null;
    }

    @Override
    public Result<Void> addBed(Bed bed) {
        if(bed.getStatus() == null){
            bed.setStatus(1);
        }
        if (bed.getIsDelete() == null){
            bed.setIsDelete(0);
        }
        if(this.save(bed)){
            return Result.success();
        }
        return Result.fail(BizCode.FAIL);
    }

    @Override
    public Result<Void> updateBed(Bed bed) {
        if(this.updateById(bed)){
            return Result.success();
        }
        return Result.fail(BizCode.FAIL);
    }

    @Override
    public Result<Void> deleteBed(Integer id) {
        if(this.removeById(id)){
            return Result.success();
        }
        return Result.fail(BizCode.FAIL);
    }
}
